import click
from app import create_app, db
from app.models import Article
from app.scraper import scrape_by_category

app = create_app()

@app.shell_context_processor
def make_shell_context():
    return {'db': db, 'Article': Article}

@app.cli.command("scrape")
def run_scraper():
    """Runs the scraper for all defined categories"""
    with app.app_context():
        categories = app.config['CATEGORIES']
        for category, url in categories.items():
            scrape_by_category(category, url)

if __name__ == '__main__':
    app.run(debug=True)
